﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UFSSWebApp
{
    public partial class managefriends : System.Web.UI.Page
    {
        UFSSservicereference.UserCreds uc = new UFSSservicereference.UserCreds();
        UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSservicereference.UFSSserviceSoapClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            uc = (UFSSservicereference.UserCreds)Session["usercreds"];
            if(!IsPostBack)
                refresh();
        }

        private void refresh()
        {
            lstFriends.Items.Clear();
            string[] friends = ussc.getFriends(uc).ToArray<string>();
            int FriendCount = friends.Length;

            for (int i = 0; i < FriendCount; i++)
                lstFriends.Items.Add(friends[i]);

            lblError.Text = "";
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                ussc.delFriend(uc, lstFriends.SelectedItem.ToString());
                refresh();
            }
            catch
            {
                lblError.Text = "Error Removing Friend.";
            }
        }

        protected void btnMessage_Click(object sender, EventArgs e)
        {
            Session.Remove("reciever");
            Session.Remove("reply");
            Session.Add("reciever", lstFriends.SelectedItem.ToString());
            Response.Redirect("~/message.aspx");
        }

        protected void btnViewProfile_Click(object sender, EventArgs e)
        {
            Session.Add("user", lstFriends.SelectedItem.ToString());
            Response.Redirect("~/userpage.aspx");
        }
    }
}